<?php
    $url = new Url();
    $arr_status = LoadConfig::$status;
    $current_url = Common::getCurrentUrl();
    $path_paging = strpos($current_url,'?') !==false ? $current_url.'&' : $current_url.'?';
    $path_paging = str_replace("?page=".$page."&","?",$path_paging);
    $path_paging = str_replace("&page=".$page."&","&",$path_paging);
?>
<script type="text/javascript">
    function ajaxQuickUpdate(id){
        var status = 0;
        if($("#status_"+id).is(":checked")){ status = 1; }
        var strUrl = "<?=$url->createUrl("embed/ajaxQuickUpdate") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                status:status,
                order_embed:$("#order_embed_"+id).val(),
                id:id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            }          
        });
    }
    function ajaxDelete(id){
        var strUrl = "<?=$url->createUrl("embed/ajaxDelete") ?>";
        if(confirm('Bạn có chắn chắn muốn xóa không ?')){
            $.ajax({
                type: "POST",
                url: strUrl,
                data: {
                    id:id
                },
                success: function(msg){
                    if(msg == 1){
                        alert('Xóa thành công');
                        location.reload();
                    }else{
                        alert(msg);
                    }
                }          
            });
        }
    }
</script>
<div class="main clearfix">

    <div class="box">
        <div class="fillter clearfix">
            <div class="fl">
                Tìm thấy <strong class="clred"><?php echo $total; ?></strong> kết quả - 
                <a href="<?php echo $url->createUrl("embed/create")?>"><input type="button" class="btn-bigblue" value=" Thêm mới "></a>
            </div>

            <div class="fr">      
                <ul class="paging">
                    <?php
                        echo Paging::show_paging_cp($max_page,$page,$path_paging);
                    ?>
                </ul>
            </div>
        </div>
        <div class="table clearfix">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr class="bg-grey">

                        <td width="5%"><strong>STT</strong></td>
                        <td width="30%"><strong>Tên bộ mã nhúng</strong></td>
                        <td width="40%"><strong>Danh sách game</strong></td>
                        <td width="5%"><strong>Thứ tự</strong></td>
                        <td width="5%"><strong>Tình trạng</strong></td>
                        <td width="15%"><strong>Quản trị</strong></td>
                    </tr>
                    <?php 
                        $i=0;
                        foreach($embed as $key=>$value){
                            $i++;
                        ?>
                        <tr>
                            <td class="middle"><?php echo $i;?></td>
                            <td class="middle"><strong><?php echo $value["title"]?></strong></td>
                            <td class="middle nopad">
                                <table width="100%" cellspacing="0" cellpadding="0" border="0">
                                    <?php foreach($value["data"] as $val){?>
                                        <tr>
                                            <td width="20%">ID:<?php echo $val["id"]?></td>
                                            <td><?php echo $val["title"]?></td>
                                        </tr>
                                        <?php }?>
                                </table>
                            </td>
                            <td><input type="text" id="order_embed_<?php echo $value["id"]?>" value="<?php echo $value["order_embed"]?>" style="width: 50px;"/></td>
                            <td><input type="checkbox" value="1" id="status_<?php echo $value["id"]?>" <?php echo $value["status"]==1 ? 'checked="checked"':'';?>> Hiển thị</td>

                            <td class="middle">
                                <a class="s14" href="javascript:ajaxQuickUpdate('<?php echo $value["id"];?>')"> Lưu </a> | 
                                <a href="<?php echo $url->createUrl("embed/edit",array("id"=>$value["id"]))?>"> Sửa </a> | 
                                <a href="javascript:ajaxDelete('<?php echo $value["id"];?>')">  Xóa  </a> 
                                </td>
                        </tr>
                        <?php }?>
                </tbody>
            </table>
        </div>
        <div class="fillter clearfix">
            <div class="fr">
                <ul class="paging">
                    <?php
                        echo Paging::show_paging_cp($max_page,$page,$path_paging);
                    ?>
                </ul>
            </div>
        </div>

    </div>
        </div>